<template>
	<view class="u-attr">
		<view @click="turnOn">
			<slot name="btn"></slot>
		</view>
		<u-popup v-model="newValue" mode="bottom" border-radius="14" :safeAreaInsetBottom="true" @close="close">
			<view class="u-model" @touchmove.stop.prevent>
				<view class="u-top dir-left-nowrap u-border-box">
					<view class="u-pic u-border-box" @click="clickImg(imgUrl)">
						<image class="u-img" :src="imgUrl"></image>
					</view>
					<view class="u-info">
						<view :class="['cross-center', 'dir-left-nowrap', themeObject.color]">
							<view class="dir-left-nowrap">
								<slot name="priceBefore"></slot>
								<view class="u-price">
									<app-price :text="textprice" v-if="is_show_price" :theme="themeObject.theme"
										:userTheme="themeObject.userTheme" :sign="sign" :price="sellPrice"
										:default-price="goods.groups[0].attr[0].price"></app-price>
									<!-- <app-price text="全款" v-if="is_show_price" :theme="themeObject.theme"
										:userTheme="themeObject.userTheme" :sign="sign" :price="allPrice"
										:default-price="goods.price"></app-price> -->
								</view>
							</view>
							<!-- <app-member-mark v-if="goods.level_show === 1" :theme="themeObject.theme"
								:userTheme="themeObject.userTheme" :sign="sign"></app-member-mark> -->
						</view>
						<view class="u-stock">库存：{{stock}}</view>
					</view>
					<view class="u-close-image" @click="close">
						<image class="bd-close-image u-border-box" src="/static/image/icon/icon-close.png"></image>
					</view>
				</view>
				<view class="u-center">
					<scroll-view class="u-scroll-view" scroll-y="true">
						<slot name="extra"></slot>

						<!-- <view v-if="goods.type === 'goods' && goods.pintuanGoods.is_alone_buy == 1 "
							class="u-attr-group u-border-box" v-for="(item, index) in newGroup" :key="index" v-if="index == 2">
							<view class="u-group-name u-text"></view>
							<view class="dir-left-wrap">
								<view
									:class="['u-group-item', attr.select ? 'u-checked ' + themeObject.back : 'u-unchecked', attr.num_0 ? 'u-attr_num_0' : '']"
									@click="storeAttr(attr.attr_id, item.attr_group_id, attr.num_0)"
									v-for="(attr, key) in item.attr_list" :key="key">
									{{attr.attr_name}}
								</view>
							</view>
						</view> -->
						<view v-for="(item, index) in newGroup" :key="index" class="u-attr-group u-border-box"
							v-if="goods.type === 'goods' && goods.pintuanGoods.isabbuy == 1 && ispt == false && goods.pintuanGoods.is_alone_buy == 1">
							<view class="u-group-name u-text">AB都买</view>
							<view class="dir-left-wrap">
								<view :class="['u-group-item', 'u-checked ' + themeObject.back ]"
									v-for="(attr, key) in item.attr_list" :key="key"
									v-if="key == item.attr_list.length-1">
									{{attr.attr_name}}
								</view>
							</view>
						</view>
						<!-- 10.25 修改文字 -->
						<view
							v-else-if="goods.type === 'goods' && goods.pintuanGoods.isabbuy == 1 && ispt == true && goods.pintuanGoods.is_alone_buy == 1"
							class="u-attr-group u-border-box" v-for="(item, index) in newGroup" :key="index">
							<view class="u-group-name u-text">AB商品</view>
							<view class="dir-left-wrap">
								<view
									:class="['u-group-item', attr.select ? 'u-checked ' + themeObject.back : 'u-unchecked', attr.num_0 ? 'u-attr_num_0' : '']"
									@click="storeAttr(attr.attr_id, item.attr_group_id, attr.num_0)"
									v-for="(attr, key) in item.attr_list" :key="key"
									v-if="key < item.attr_list.length-1">
									{{attr.attr_name}}
								</view>
							</view>
						</view>
						<!-- 10.25 修改文字 将拼团修改成其他的文字 -->
						<view v-else-if="goods.type === 'goods' && goods.pintuanGoods.isabbuy == 1"
							class="u-attr-group u-border-box" v-for="(item, index) in newGroup" :key="index">
							<view class="u-group-name u-text">AB商品</view>
							<view class="dir-left-wrap">
								<view
									:class="['u-group-item', attr.select ? 'u-checked ' + themeObject.back : 'u-unchecked', attr.num_0 ? 'u-attr_num_0' : '']"
									@click="storeAttr(attr.attr_id, item.attr_group_id, attr.num_0)"
									v-for="(attr, key) in item.attr_list" :key="key" v-if="key < item.attr_list.length">
									{{attr.attr_name}}
								</view>
							</view>
						</view>
						<view v-else-if="goods.type === 'goods' && goods.pintuanGoods.isabbuy == 0"
							class="u-attr-group u-border-box" v-for="(item, index) in newGroup" :key="index">
							<view class="u-group-name u-text">{{item.attr_group_name}}</view>
							<view class="dir-left-wrap">
								<view
									:class="['u-group-item', a.select ? 'u-checked ' + themeObject.back : 'u-unchecked', a.num_0 ? 'u-attr_num_0' : '']"
									@click="storeAttr(a.attr_id, item.attr_group_id, a.num_0)"
									v-for="(a, k) in item.attr_list" :key="k">
									{{a.attr_name}}
								</view>
							</view>
						</view>
						<view v-else-if="goods.type === 'goods'" class="u-attr-group u-border-box"
							v-for="(item, index) in newGroup" :key="index">
							<view class="u-group-name u-text">{{item.attr_group_name}}</view>
							<view class="dir-left-wrap">
								<view v-for="(attr, key) in item.attr_list" :key="key"
									@click="storeAttr(attr.attr_id, item.attr_group_id, attr.num_0)"
									:class="['u-group-item', attr.select ? 'u-checked ' + themeObject.back : 'u-unchecked', attr.num_0 ? 'u-attr_num_0' : '']">
									{{attr.attr_name}}
								</view>
							</view>
						</view>
						<!-- <view class="u-attr-group u-border-box"
							v-if="goods.type === 'goods' && goods.pintuanGoods.isabbuy == 1">
							<view class="u-group-name u-text">AB拼团</view>
							<view class="dir-left-wrap">
								<view class="u-group-item u-line-2" @click="abcheck(index,item.pic_url,item.stock,item.price)"
									:class="[item.stock == 0 ? 'u-attr_num_0' : '' , changeanum == index ? 'u-checked ' + themeObject.back : 'u-unchecked']"
									v-for="(item, index) in goods.attr" :key="index" v-if="index < 2">
									{{item.attr_list[0].attr_name}}
								</view>
							</view>
						</view> -->
						<view class="u-number dir-left-nowrap main-between cross-center">
							<view class="u-text">数量</view>
							<view class="dir-left-nowrap u-input-box">
								<view @click.stop="numberSub"
									:class="[number <=1 ? 'u-reduced-1' : 'u-reduced-0', 'u-number-btn']"></view>
								<input @blur="numberBlur" type="number" class="u-input" v-model="number">
								<view @click.stop="numberAdd" class="u-number-btn u-added-1"></view>
							</view>
						</view>
					</scroll-view>
				</view>
				<view class="u-bottom dir-left-nowrap">
					<!-- 加入购物车 -->
					<view v-if="is_show_left && (goods.type === 'goods' || is_must_left)" class="box-grow-1"
						:class="[!$slots.left_slot ? themeObject.sBack + ' u-btn ' + themeObject.color: '']"
						@click="leftSubmit">
						<slot name="left_slot"></slot>
						<template v-if="!$slots.left_slot">{{leftText}}</template>
					</view>
					<view v-if="is_show_right" class="box-grow-1" @click="rightSubmit"
						:class="[!$slots.right_slot ? themeObject.back + ' u-btn u-btn-color' : '']">
						<slot name="right_slot"></slot>
						<template v-if="!$slots.right_slot">{{rightText}}</template>
					</view>
					<template v-if="$slots.right">
						<slot name="right"></slot>
					</template>
				</view>
			</view>
		</u-popup>
		<!-- 9.30 10.9  10.11 修改样式 -->
		<u-popup :customStyle="custyle" v-model="isshoe" mode="center" :maskCloseAble="false" border-radius="14"
			:safeAreaInsetBottom="true" @close="close">
			<view class="gold-model" @touchmove.stop.prevent>
				<view class="closegold" @click="closegold">
					关闭<image src="/static/image/close.png" mode=""></image>
				</view>
				<!-- 10.14 修改文字样式 -->
				<view class="" style="text-align: center;margin-bottom: 20rpx;">
					金币
					<!-- 白条 -->使用说明
				</view>
				<!-- 11.12 rightSubmit(1) -->
				<view class="">
					1.您当前的金币数量为{{integral}}个，当前商品抵扣所需金币{{goods.original_discount_price1}}个，可抵扣{{goods.original_discount_price1}}元
					<view class="gold-use" :class="['u-checked ' + themeObject.back]" @click="toshare(1)"
						v-if="integral >= goods.original_discount_price1">使用金币</view>
					<view class="gold-use unchecked" v-else>
						您当前金币数量不足，不可使用金币
					</view>
				</view>
				<!-- 11.12 rightSubmit(2) -->
				<!-- 2.本商品可使用金币白条抵扣，抵扣的{{goods.original_discount_price1}}金币将在商品核销后扣除 -->
				<!-- <view class="">
					2.使用金币白条，可抵用{{goods.original_discount_price1}}元
					<view class="gold-use" :class="['u-checked ' + themeObject.back]" @click="toshare(2)">使用白条
					</view>
				</view> -->
				<!-- 10.11 -->
				<!-- <view class="" style="margin-top: 72rpx;">
					3.<text style="color: #eb0f13;">说明</text>：订单核销后，可获取{{goods.original_price_discount}}金币。
					<text class="">
						使用白条归还{{goods.original_discount_price1}}金币，赠送{{goods.original_price_discount - goods.original_discount_price1}}金币。
					</text>
					<text class="">
						可选择不使用金币扣除，购买核销后，可获得金币。
					</text>
				</view> -->
			</view>
		</u-popup>
		<!-- 11.12 是否使用分享价格购买 -->
		<u-popup :customStyle="custyle" v-model="isshoj" mode="center" :maskCloseAble="false" border-radius="14"
			:safeAreaInsetBottom="true" @close="close">
			<view class="gold-model" @touchmove.stop.prevent>
				<view class="closegold" @click="closeygold">
					关闭<image src="/static/image/close.png" mode=""></image>
				</view>
				<view class="" style="text-align: center;margin-bottom: 20rpx;">
					分享价购买
				</view>
				<view class="">
					1.不分享不可购买
					<!-- 使用非分享价购买 -->
					<!-- <view class="gold-use" :class="['u-checked ' + themeObject.back]" @click="rightSubmit(bshare)">直接购买
					</view> -->
					<view class="gold-use" :class="['u-checked ' + themeObject.back]" @click="rightSubmit(bshare,1)"
						v-if="issharesuc">购买</view>
					<view class="" v-else>
						<view class="gold-use" :class="['u-checked ' + themeObject.back]"
							@click="jump('/pages/goods/sharegold/sharegold?sharecon='+JSON.stringify(goods.params)+'&goodsid='+goods.id+'&goodsharepic='+goods.app_share_pic+'&goodsharetitle='+goods.app_share_title+'&mall_id='+goods.mall_id)">
							分享商品
						</view>
						<view class="gold-use unchecked"
							@click="jump('/pages/goods/sharegold/sharegold?sharecon='+JSON.stringify(goods.params)+'&goodsid='+goods.id+'&goodsharepic='+goods.app_share_pic+'&goodsharetitle='+goods.app_share_title+'&mall_id='+goods.mall_id)">
							请先分享再购买吧
						</view>
					</view>
				</view>
				<view class="">
					2.使用分享价购买
					<view class="gold-use" :class="['u-checked ' + themeObject.back]" @click="rightSubmit(bshare,1)"
						v-if="issharesuc">购买</view>
					<view class="" v-else>
						<view class="gold-use" :class="['u-checked ' + themeObject.back]"
							@click="jump('/pages/goods/sharegold/sharegold?sharecon='+JSON.stringify(goods.params)+'&goodsid='+goods.id+'&goodsharepic='+goods.app_share_pic+'&goodsharetitle='+goods.app_share_title+'&mall_id='+goods.mall_id)">
							分享商品
						</view>
						<view class="gold-use unchecked"
							@click="jump('/pages/goods/sharegold/sharegold?sharecon='+JSON.stringify(goods.params)+'&goodsid='+goods.id+'&goodsharepic='+goods.app_share_pic+'&goodsharetitle='+goods.app_share_title+'&mall_id='+goods.mall_id)">
							请先分享再购买吧
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup :customStyle="custyle" v-model="isshos" mode="center" :maskCloseAble="false" border-radius="14"
			:safeAreaInsetBottom="true" @close="close">
			<view class="gold-model" @touchmove.stop.prevent>
				<view class="closegold" @click="closesgold">
					关闭<image src="/static/image/close.png" mode=""></image>
				</view>
				<view class="" style="text-align: center;margin-bottom: 20rpx;">
					成为珠宝店主后可购买一次
				</view>
				<view class="" v-if="!ishopkeeper">
					<view class="gold-use" :class="['u-checked ' + themeObject.back]"
						@click="jump('/pages/bepartner/apply/apply')">
						成为珠宝店主
					</view>
					<view class="gold-use unchecked" @click="jump('/pages/bepartner/apply/apply')">
						请先成为珠宝店主再购买吧
					</view>
				</view>
				<view class="" v-if="ishopkeeper && !nocbp">
					<view class="gold-use" :class="['u-checked ' + themeObject.back]" @click="rightSubmit">
						已成为珠宝店主可直接购买
					</view>
					<view class="gold-use" :class="['u-checked ' + themeObject.sBack]" @click="rightSubmit">
						直接购买
					</view>
				</view>
				<view class="" v-if="ishopkeeper && nocbp">
					<view class="gold-use unchecked">
						您已购买购买过啦
					</view>
					<view class="gold-use unchecked">
						不可以重复购买哦~
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import uPopup from '../../basic-component/u-popup/u-popup.vue';
	import appPrice from "../goods/app-price.vue";
	import appMemberMark from "../app-member-mark/app-member-mark.vue";

	export default {
		name: "u-attr",
		props: {
			value: {
				type: Boolean
			},
			goods: {
				type: Object
			},
			themeObject: {
				type: Object
			},
			checked: {
				type: Object
			},
			goodsdetail: {
				type: Object
			},
			is_show_price: {
				type: Boolean,
				default: true
			},
			ispt: {
				type: Boolean,
				default: true
			},
			is_show_left: {
				type: Boolean,
				default: true
			},
			is_must_left: {
				type: Boolean,
				default: true
			},
			is_show_right: {
				type: Boolean,
				default: true
			},
			leftText: {
				type: String,
				default: '加入购物车'
			},
			rightText: {
				type: String,
				default: '支付定金'
			},
			textprice: {
				type: String,
				default: '定金'
			},
			leftFunc: {
				type: Boolean
			},
			rightFunc: {
				type: Boolean
			},
			sign: {
				type: String
			},
			again: {
				type: Number
			},
			store_id: {
				type: Number
			},
			video_id: {
				type: Number
			},
			// 9.30
			// isshoe: {
			// 	type: Boolean,
			// 	default: false
			// }
			// 11.12 是否分享成功
			issharesuc: {
				type: Boolean,
				default: false
			},
			// 11.12 是否是黄金
			ishj: {
				type: Boolean,
				default: false
			},
			// 是否下过单
			nocbp: {
				type: Boolean,
				default: false
			},
			// 是否是店主
			ishopkeeper: {
				type: Boolean,
				default: false
			},
		},
		data() {
			return {
				newValue: false,
				picUrl: null,
				newGroup: [],
				number: 1,
				changeanum: 0,
				abbuy_type: '',
				// 9.30 金币 页面 样式
				custyle: {
					// 'background': '#fff'
					'background': 'rgba(226, 226, 226, 0.3)',
				},
				isshoe: false,
				integral: 0,

				// 11.12 是否分享价购买
				isshoj: false,
				// 11.12 在使用金币白条的基础上使用分享价
				bshare: 0,

				// 成为店主可购买一元商品
				isshos: false
			}
		},
		methods: {
			jump(item) {
				if (this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken === null) {
					this.$store.dispatch('user/accessToken');
					return;
				}
				uni.navigateTo({
					url: item
				})
			},
			// 9.30
			closegold() {
				this.isshoe = false
				this.bshare = 0
			},
			// 11.12 是否分享价购买
			closeygold() {
				this.isshoj = false
			},
			// 一元购
			closesgold() {
				this.isshos = false
			},
			// 10.9 查询自己的所有金币
			allgold() {
				let that = this
				that.$request({
					url: that.$api.integral_mall.index,
				}).then(response => {
					if (response.code === 0) {
						that.integral = response.data.userInfo.integral;
					} else {
						if (response.msg) {
							uni.showToast({
								title: response.msg,
								icon: 'none',
								duration: 1000
							});
						}
					}
				})
			},
			// 选择AB商品
			abcheck(id, pic_url, stock, price) {
				this.changeanum = id
				this.picUrl = pic_url
				// this.stock = stock
				// this.sellPrice = price
			},
			close: function() {
				this.$emit('input', false);
				// 9.30 // 10.11 不依赖于bottom弹窗
				// this.isshoe = false
			},
			turnOn: function() {
				this.$emit('input', true);
			},
			inArray: function(newVal, arr) {
				return arr.some(v => {
					return newVal === v;
				});
			},
			identifier: function(copyGroup, attrNum_0, select) {
				copyGroup.forEach(f => {
					f.attr_list.forEach(c => {
						let param = `${f.attr_group_id}-${c.attr_id}`;
						this.inArray(param, attrNum_0) && !this.inArray(param, select) ? c.num_0 =
							true : c.num_0 = false;
					});
				});
			},
			selectCheck: function(copyAttr, attrNum_0, select) {
				copyAttr.forEach(f => {
					let arr = [];
					let sign = 0;
					f.attr_list.forEach(c => {
						let param = `${c.attr_group_id}-${c.attr_id}`;
						if (!this.inArray(param, select)) {
							sign += 1;
							arr.push(param);
						}
					});
					// console.log(f, 'f', 111111);
					// console.log(sign);
					if (f.stock === 0 && sign <= 1) Array.prototype.push.apply(attrNum_0, arr);
					if (sign === 0) this.$emit('check', f, 1);
					// console.log(attrNum_0);
					// console.log(select);
				});
			},
			storeAttr: function(attr_id, group_id, num_0) {
				// console.log(55555);
				if (num_0 === true) return;
				let newGroup = this.newGroup;
				// console.log(this.newGroup, '0000');
				let copyAttr = this.copyAttr;
				let select = [];
				newGroup.forEach((i, index) => {
					let attr_list = i.attr_list;
					attr_list.forEach((k) => {
						if (i.attr_group_id === group_id) k.attr_id === attr_id ? k.select = true : k
							.select = false;
						if (k.select === true) {
							select.push(`${i.attr_group_id}-${k.attr_id}`);
							if (index === 0) this.picUrl = k.pic_url;
						}
					});
				});
				let attrNum_0 = [];
				this.selectCheck(copyAttr, attrNum_0, select);
				this.$nextTick(() => {
					if (this.number > this.stock) this.number = this.stock;
				});
				this.identifier(newGroup, attrNum_0, select);
				/* if (attr_id == 1) {
					this.abbuy_type = 'A'
				} else if (attr_id == 2) {
					this.abbuy_type = 'B'
				} else if (attr_id == 3) {
					this.abbuy_type = 'AB'
				} */
			},
			firstSelect: function() {
				// console.log(99999);
				if (!this.copyGroup || !this.copyAttr) return;
				let copyGroup = this.copyGroup;
				// console.log(this.copyAttr);
				let copyAttr = this.copyAttr;
				let groupLength = copyGroup.length;
				let select = [];
				copyAttr.forEach(i => {
					let attr_list = i.attr_list;
					attr_list.forEach(j => {
						let attr_group_id = j.attr_group_id;
						copyGroup.forEach(k => {
							if (attr_group_id === k.attr_group_id) {
								let groups_attr_list = k.attr_list;
								groups_attr_list.forEach(g => {
									if (g.attr_id === j.attr_id) {
										if (i.stock > 0) {
											if (groupLength > 0) {
												g.select = true;
												select.push(
													`${k.attr_group_id}-${g.attr_id}`
												);
												if (groupLength === copyGroup.length) {
													this.picUrl = g.pic_url;
												}
												groupLength--;
											}
										}
									}
								});
							}
						});
					});
				});
				let attrNum_0 = [];
				this.selectCheck(copyAttr, attrNum_0, select);
				this.identifier(copyGroup, attrNum_0, select);
				this.newGroup = copyGroup;
			},
			numberBlur: function(e) {
				let value = parseInt(e.detail.value);
				if (!value) value = 1;
				if (value > this.stock) {
					value = this.stock;
					uni.showToast({
						title: '库存不足',
						icon: 'none'
					});
				}
				this.number = value;
			},
			numberSub: function() {
				let value = this.number;
				if (value > 1) {
					value--;
					this.number = value;
				}
			},
			numberAdd: function() {
				let value = this.number;
				value++;
				if (value > this.stock) {
					value = this.stock;
					uni.showToast({
						title: '库存不足',
						icon: 'none'
					});
				}
				this.number = value;
			},
			leftSubmit: function() {
				if (this.leftFunc === true) {
					this.$emit('leftFunc', this.number);
				} else {
					this.cart();
				}
				this.close();
			},
			// 11.12 
			toshare(wheid = {}, shareid = 0) {
				if (this.goods.params && this.goods.params.isshare && this.goods.params.isshare == 1) {
					this.isshoj = true
					this.bshare = wheid
				} else {
					this.rightSubmit(wheid)
				}
			},
			// 11.12 添加是否分享购买 
			/** 购买
			 *  wheid 使用金币白条或不使用
			 *  shareid 是否分享
			 * */
			rightSubmit: function(wheid = {}, shareid = 0) {
				if (this.$store.state.user.accessToken === '' || this.$store.state.user.accessToken === null) {
					this.$store.dispatch('user/accessToken');
					return;
				}
				// 10.9 金币小于可抵用金币数量
				// if(this.integral < this.goods.original_discount_price1){
				// 	return
				// }
				let attrs = [];
				this.checked.attr_list.forEach(item => {
					attrs.push({
						attr_id: item.attr_id,
						attr_group_id: item.attr_group_id
					});
				});
				let goods = {
					mch_id: this.goods.mch_id ? this.goods.mch_id : 0,
					goods_list: [{
						id: this.goods.id,
						attrs,
						num: this.number,
						cat_id: 0,
						goods_attr_id: this.checked.id
					}],
					mall_id: this.goods.mall_id,
					// 添加从哪家店买的 8.23（别人（分享）的小店，精品店，）
					v_id: this.store_id,
					// 添加从哪个视频进来的（嗨我来了）
					video_id: this.video_id,
					// abbuy_type:this.abbuy_type
				}
				// 11.12 存在分享设置且 分享人数已够
				if (shareid == 1) {
					goods.isgoodshare = 1
				} else if (shareid == 0) { // 11.15 添加 没有分享
					if (this.goods.params && this.goods.params.isshare && this.goods.params.isshare == 1) { // 有分享设置
						goods.isgoodshare = 2
					} else { // 无分享设置
						goods.isgoodshare = 0
					}
				}
				if (this.rightFunc === true) {
					this.$emit('rightFunc', goods, this.abbuy_type);
				} else {
					// 10.9 金币白条跳转
					if (!isNaN(Number(wheid))) {
						this.shop(goods, wheid, shareid);
					} else {
						this.shop(goods, {}, shareid);
					}
				}
				this.close();
				// 10.11 不依赖于bottom弹窗
				this.closegold()
				// 11.12 分享价 不依赖于bottom弹窗
				this.closeygold()
				// 一元购
				this.closesgold()
			},
			shop: function(goods, wheid = {}, shareid = 0) {
				// 10.9
				let url = '/pages/order-submit/order-submit?mch_list=' + JSON.stringify([goods]) + '&store_id=' + this
					.store_id
				if (!isNaN(Number(wheid))) {
					url = url + '&jfbt_type=' + wheid
				}
				// 11.12 如果是黄金
				if (this.ishj) {
					url = url + '&ishj=' + this.ishj
				}
				if (this.goods.mall_id) {
					url = url + '&mall_id=' + this.goods.mall_id
					// + '&preview_url=' + this.storemall.order.preview
				}
				// 11.15 分享设置打开与否
				if (this.goods.params && this.goods.params.isshare && this.goods.params.isshare == 1) {
					if (shareid == 1) {
						url = url + '&isfxg=1'
					} else {
						url = url + '&isfxg=2'
					}
				} else {
					url = url + '&isfxg=0'
				}
				uni.navigateTo({
					url: url
				});
			},
			cart: function() {
				// console.log(this.goods);
				let vsid = {
					// 添加购物车加上从哪家店点击进来的
					v_id: this.store_id,
					// 添加从哪个视频进来的（嗨我来了）
					video_id: this.video_id,
				}
				vsid = JSON.stringify(vsid)
				if (this.goods.type === 'ecard') return;
				let url = this.$api.cart.add
				if (this.goods.mall_id > 1) {
					url = this.$siteInfo.apiroot + '?_mall_id=' + this.goods.mall_id + '&r=' + this.$apiUrl.cart.add
				}
				this.$request({
					url: url,
					method: 'post',
					data: {
						mch_id: this.goods.mch_id ? this.goods.mch_id : 0,
						goods_id: this.checked.goods_id,
						attr: this.checked.id,
						num: this.number,
						vform: vsid
					}
				}).then(res => {
					if (res.code === 0) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						this.$emit('cart', this.checked, this.number);
						this.close();
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 2500
						});
					}
				});
			},
			clickImg(src) {
				uni.previewImage({
					current: 0,
					urls: [src]
				});
			}
		},
		components: {
			uPopup,
			appPrice,
			appMemberMark
		},
		computed: {
			imgUrl: function() {
				if (this.ispt == false) {
					this.storeAttr(3, 1)
					return this.picUrl;
				} else {
					if (this.picUrl) {
						return this.picUrl;
					} else if (this.goods) {
						return this.goods.cover_pic;
					} else {
						return this.goods.cover_pic;
					}
				}
			},
			stock: function() {
				if (!this.$validation.isEmpty(this.checked)) {
					return this.checked.stock;
				} else if (!this.$validation.isEmpty(this.goods)) {
					return this.goods.goods_num;
				}
			},
			sellPrice: function() {
				if (!this.$validation.isEmpty(this.checked)) {
					return this.goods.level_show === 1 ? this.checked.price_member : this.checked.price;
				} else if (!this.$validation.isEmpty(this.goods)) {
					// return this.goods.hasOwnProperty('price_min') ? this.goods.price_min : this.goods.price;
					return this.goods.groups[0].attr[0].price;
				}
			},
			/* allPrice: function() {
				console.log(this.goodsdetail, 'goodsdetail');
				console.log(this.goods, 'goods');
				console.log(this.checked, 'checked');
				if (!this.$validation.isEmpty(this.checked)) {
					return this.goods.level_show === 1 ? this.checked.price_member : this.checked.price;
				} else if (!this.$validation.isEmpty(this.goods)) {
					return this.goods.hasOwnProperty('price_min') ? this.goods.price_min : this.goods.price;
				}
			}, */
			copyGroup: function() {
				if (!this.goods) return;
				let group = this.$utils.deepClone(this.goods.attr_groups);
				for (let i = 0; i < group.length; i++) {
					group[i].attr_list.forEach(item => {
						item.select = false;
						item.num_0 = false;
					});
				}
				return group;
			},
			copyAttr: function() {
				if (!this.goods) return;
				if (this.goods.pintuanGoods != undefined && this.goods.pintuanGoods.isabbuy == 1) {
					return this.$utils.deepClone(this.goods.groups[0].attr);
				} else if (this.goods.pintuanGoods != undefined && this.goods.pintuanGoods.isabbuy == 0) {
					return this.$utils.deepClone(this.goods.groups[0].attr);
				} else {
					return this.$utils.deepClone(this.goods.attr);
				}
			}
		},
		watch: {
			value: {
				handler(newVal) {
					this.newValue = newVal;
					if (newVal === false) return;
					if (this.$validation.isEmpty(this.checked)) this.$utils.throttle(this.firstSelect, 800);
				},
				immediate: true
			},
			number: {
				handler(newVal) {
					this.$emit('check', this.checked, newVal);
				}
			},
			again: {
				handler() {
					this.firstSelect();
				}
			},
			// 10.11 不依赖于bottom弹窗
			isshoe: {
				handler(val) {
					if (val) {
						this.close()
					}
				}
			},
			// 11.12 是否有分享人数，分享价购买
			isshoj: {
				handler(val) {
					if (val) {
						this.close()
					}
				}
			},
			// 一元购
			isshos: {
				handler(val) {
					if (val) {
						this.close()
					}
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.u-model {
		width: 750upx;
	}

	/* 10.11 */
	.gold-model {
		// background: rgba(#eb0f13, .1);
		background: #fff;
		width: 670rpx;
		padding: 36rpx;
		font-size: 36rpx;
		line-height: 72rpx;
		// font-weight: bold;

		.closegold {
			display: flex;
			align-items: center;
			justify-content: flex-end;

			image {
				width: 40rpx;
				height: 40rpx;
				margin-left: 30rpx;
			}
		}

		.gold-use {
			text-align: center;

			&.unchecked {
				background-color: #8f8f8f;
				color: #FFFFFF;
			}
		}
	}

	.u-top {
		margin: 0 24upx;
		border-bottom: 1upx solid #e2e2e2;
		height: 140upx;
	}

	.u-close-image {
		width: 54upx;
		height: 78upx;
		padding: 24upx 0 24rpx 24rpx;
		margin-left: 24rpx;
	}

	.bd-close-image {
		width: 30upx;
		height: 30upx;
	}

	.u-pic {
		width: 200rpx;
		height: 200rpx;
		padding: 4upx;
		border-radius: 8rpx;
		position: relative;
		top: -64upx;
		background-color: #ffffff;
	}

	.u-img {
		width: 192rpx;
		height: 192rpx;
		background-color: #ffffff;
	}

	.u-info {
		width: 424upx;
		height: 136upx;
		padding: 45upx 0 0 24upx;
	}

	.u-scroll-view {
		width: 100%;
		max-height: 650upx;
	}

	.u-attr-group {
		margin: 24upx 32upx 0 32upx;
		border-bottom: 1upx solid #e2e2e2;
	}

	.u-number {
		height: 124upx;
		margin: 0 32upx;
	}

	.u-group-name {
		margin-bottom: 20upx;
	}

	.u-group-item {
		padding: 15upx 24upx;
		border-radius: 8upx;
		margin: 0 20upx 20upx 0;
		font-size: 26upx;
	}

	.u-checked {
		color: #ffffff;
	}

	.u-unchecked {
		background-color: #f2f2f2;
		color: #353535;
	}

	.u-attr_num_0 {
		background-color: #f7f7f7;
		color: #cdcdcd;
	}

	.u-stock {
		font-size: 24upx;
		color: #999999;
	}

	.u-price {
		margin-right: 12upx;
		display: flex;
		align-items: center;
	}

	.u-input {
		width: 88upx;
		height: 60upx;
		background-color: #f7f7f7;
		font-size: 20upx;
		color: #353535;
		text-align: center;
	}

	.u-input-box {
		width: 218upx;
	}

	.u-number-btn {
		height: 60upx;
		width: 60upx;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		background-position: center;
	}

	.u-number-btn:first-child {
		margin-right: 5upx;
	}

	.u-number-btn:last-child {
		margin-left: 5upx;
	}

	.u-reduced-1 {
		background-image: url("../../../static/image/icon/can-be-reduced.png");
	}

	.u-reduced-0 {
		background-image: url("../../../static/image/cart/can-be-reduced.png");
	}

	.u-added-1 {
		background-image: url("../../../static/image/cart/can-be-added.png");
	}

	.u-text {
		font-size: 26upx;
		color: #666666;
	}

	.u-bottom {
		height: 110upx;
	}

	.u-btn {
		text-align: center;
		line-height: 110upx;
	}

	.u-btn-color {
		color: #ffffff;
	}
</style>
